package com.example.b_308.myapplication.view.user.login;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.b_308.myapplication.R;
import com.example.b_308.myapplication.comment.utils.Global;
import com.example.b_308.myapplication.view.base.BaseActivity;

/**
 * Created by B-308 on 2017/11/20.
 */
public class ForgetpwActivity extends BaseActivity implements View.OnClickListener{
    EditText et_phone_forget, et_vertify_forget;
    ImageView iv_pf_delete, iv_vf_delete;
    Button but_get_forget,but_next_forget;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initListenerForget();
    }

    private void initListenerForget() {
        iv_pf_delete.setOnClickListener(this);
        iv_vf_delete.setOnClickListener(this);
        but_get_forget.setOnClickListener(this);
        but_next_forget.setOnClickListener(this);
        et_phone_forget.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(s.length() == 0){
                    iv_pf_delete.setVisibility(View.GONE);
                }else{
                    iv_pf_delete.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        et_vertify_forget.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(s.length() == 0){
                    iv_vf_delete.setVisibility(View.GONE);
                    but_next_forget.setSelected(false);
                }else{
                    iv_vf_delete.setVisibility(View.VISIBLE);
                    but_next_forget.setSelected(true);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }

    private void initView() {
        setContentView(R.layout.activity_forgetpw);
        getTitleBar().setTitle(Global.getString(R.string.forget_password));
        getTitleBar().getTv_setting().setVisibility(View.GONE);
        getTitleBar().getIv_setting().setVisibility(View.GONE);
        getTitleBar().getTv_return().setVisibility(View.GONE);
        et_phone_forget = findView(R.id.et_phone_forget);
        et_vertify_forget = findView(R.id.et_vertify_forget);
        iv_pf_delete = findView(R.id.iv_pf_delete);
        iv_vf_delete = findView(R.id.iv_vf_delete);
        but_get_forget = findView(R.id.but_get_forget);
        but_next_forget = findView(R.id.but_next_forget);
    }

    @Override
    public void fail(String message) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_pf_delete:
                et_phone_forget.setText("");
                break;
            case R.id.iv_vf_delete:
                et_vertify_forget.setText("");
                break;
            case R.id.but_get_forget:
                break;
            case R.id.but_next_forget:
                tend2(ModifyActivity.class);
                break;
        }

    }
}
